package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.CardCouponReceiveRecordDao;
import com.tequila.core.service.CardCouponReceiveRecordService;
import com.tequila.domain.dto.CardCouponReceiveRecordDto;
import com.tequila.domain.entity.CardCouponReceiveRecord;
import com.tequila.domain.query.CardCouponReceiveRecordQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CardCouponReceiveRecordServiceImpl implements CardCouponReceiveRecordService {
    public static final Logger logger = LoggerFactory.getLogger(CardCouponReceiveRecordServiceImpl.class);

    @Resource
    private CardCouponReceiveRecordDao cardCouponReceiveRecordDao;

    @Override
    public Pagination<CardCouponReceiveRecordDto> queryPageListByParam(CardCouponReceiveRecordQuery query) {
        Assert.assertNotNull(query);
        int total = cardCouponReceiveRecordDao.queryPageCountByParam(query);

        List<CardCouponReceiveRecordDto> list = Lists.newArrayList();
        if (total > 0) {
            list = cardCouponReceiveRecordDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public CardCouponReceiveRecordDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        CardCouponReceiveRecord cardCouponReceiveRecord = cardCouponReceiveRecordDao.queryById(id);
        CardCouponReceiveRecordDto cardCouponReceiveRecordDto = new CardCouponReceiveRecordDto();
        BeanHelper.copyProperties(cardCouponReceiveRecordDto,cardCouponReceiveRecord);
        return cardCouponReceiveRecordDto;
    }

    @Override
    public List<CardCouponReceiveRecordDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponReceiveRecordDao.queryByIdList(idList);
    }

    @Override
    public List<CardCouponReceiveRecordDto> queryListByParam(CardCouponReceiveRecordQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return cardCouponReceiveRecordDao.queryListByParam(query);
    }


    @Override
    public Long insert(CardCouponReceiveRecord entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponReceiveRecordDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(CardCouponReceiveRecord entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponReceiveRecordDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(CardCouponReceiveRecord param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponReceiveRecordDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(CardCouponReceiveRecord param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponReceiveRecordDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return cardCouponReceiveRecordDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponReceiveRecordDao.deleteByIdList(idList);
    }
}
